package com.hns.frame.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;

/**
 * mybatis DAO共通工具
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Component
public class SqlMapDao extends SqlSessionDaoSupport {
    
    /**
     * 查询只有一个结果集的数据
     * @param statement sql语句
     * @return  查询结果
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    public Object selectOne(String statement) {
        return this.getSqlSession().selectOne(statement);
    }
    
    /**
     * 带参数查询只有一个结果集的数据
     * @param statement sql语句
     * @return  查询结果
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    public Object selectOne(String statement, Object parameter) {
        return this.getSqlSession().selectOne(statement, parameter);
    }
    
    /**
     * 根据查询语句得出map
     * @param statement sql语句
     * @param mapKey
     * @return
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     */
    public Map selectMap(String statement, String mapKey) {
        return this.getSqlSession().selectMap(statement, mapKey);
    }
    
    public Map selectMap(String statement, Object parameter, String mapKey) {
        return this.getSqlSession().selectMap(statement, parameter, mapKey);
    }
    
    public Map selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) {
        return this.getSqlSession().selectMap(statement, parameter, mapKey, rowBounds);
    }
    
    public List selectList(String statement) {
        return this.getSqlSession().selectList(statement);
    }
    
    public List selectList(String statement, Object parameter) {
        return this.getSqlSession().selectList(statement, parameter);
    }
    
    /**
     * @param statement
     * @param parameter
     * @param rowBounds 翻页信息
     * @return
     * @author:Fisher
     * @email:zhuangcaijin@126.com
     * @创建日期:2014-4-17
     * @功能说明：查询翻页的记录
     */
    public List selectList(String statement, Object parameter, RowBounds rowBounds) {
        return this.getSqlSession().selectList(statement, parameter, rowBounds);
    }
    
    public void select(String statement, ResultHandler handler) {
        this.getSqlSession().select(statement, handler);
    }
    
    public void select(String statement, Object parameter, ResultHandler handler) {
        this.getSqlSession().select(statement, parameter, handler);
    }
    
    public void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler) {
        this.getSqlSession().select(statement, parameter, rowBounds, handler);
    }
    
    public int update(String statement, Object parameter){
        return this.getSqlSession().update(statement, parameter);
    }
    
    public int update(String statement){
    	return this.getSqlSession().update(statement);
    }
    
    public int delete(String statement){
        return this.getSqlSession().delete(statement);
    }
    
    public int delete(String statement, Object parameter){
        return this.getSqlSession().delete(statement, parameter);
    }
    
    public int insert(String statement){
        return this.getSqlSession().insert(statement);
    }
    
    public int insert(String statement, Object parameter){
        return this.getSqlSession().insert(statement, parameter);
    }
}
